package com.ihisomp.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.ihisomp.entity.SysUserWork;
import com.ihisomp.mapper.SysUserWorkMapper;
import com.ihisomp.service.ISysUserWorkService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 * 用户与工种关联表 服务实现类
 * </p>
 *
 * @author zy
 * @since 2022-04-15
 */
@Service
public class SysUserWorkServiceImpl extends ServiceImpl<SysUserWorkMapper, SysUserWork> implements ISysUserWorkService {

    /**
     * 根据用户编码删除用户对应工种
     *
     * @param userKey
     * @return
     */
    @Override
    public int deleteByUserKey(String userKey) {
        return baseMapper.deleteByUserKey(userKey);
    }

    /**
     * 根据用户编码查询用户对应工种
     *
     * @param userKey
     * @return
     */
    @Override
    public List<String> getWorkByUserKey(String userKey) {
        QueryWrapper<SysUserWork> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("user_key", userKey);
        queryWrapper.orderByAsc("type_of_work");
        List<SysUserWork> sysUserWorks = baseMapper.selectList(queryWrapper);
        List<String> list = new ArrayList();
        for (int i = 0; i < sysUserWorks.size(); i++) {
            list.add(sysUserWorks.get(i).getTypeOfWork());
        }
        return list;
    }
}
